var mysql = require('mysql');

var pool = mysql.createPool({
    host: 'localhost',
    port: '3306',
    user: 'root',
    password: '139906', //'b123',
    database: 'yg_manager'
});
// var pool = mysql.createPool({
//     host: 'hdm721909112.my3w.com',
//     port: '3306',
//     user: 'hdm721909112',
//     password: 'Kf820312',
//     database: 'hdm721909112_db'
// });

function query(sql, parameter, callback) {
    pool.getConnection(function (err, conn) {
        if (err) {
            callback(err, null, null);
        } else {
            conn.query(sql, parameter, function (qerr, vals, fields) {
                //释放连接
                conn.release();
                //事件驱动回调
                callback(qerr, vals, fields);
            });
        }
    });
};

exports.query = query;